Skip to content

Add ParseVersionValue helper to eliminate version parsing duplication#8248

Merged
pelikhan merged 2 commits intomainfrom
copilot/create-parse-version-value-helper
Dec 31, 2025
Merged

Add ParseVersionValue helper to eliminate version parsing duplication#8248
pelikhan merged 2 commits intomainfrom
copilot/create-parse-version-value-helper

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

Version value coercion logic (string/int/float → string) was duplicated across three locations: engine configuration parsing and two MCP tool version handlers.

Changes

  • Added stringutil.ParseVersionValue(): Handles string, int, int64, uint64, float64 types. Returns empty string for unsupported types.
  • Refactored three usage sites:
    • pkg/workflow/engine.go (engine version field)
    • pkg/parser/mcp.go (GitHub MCP Docker image version)
    • pkg/parser/mcp.go (Playwright Docker image version)

Example

Before:

switch v := version.(type) {
case string:
    versionStr = v
case int:
    versionStr = fmt.Sprintf("%d", v)
case int64:
    versionStr = fmt.Sprintf("%d", v)
case uint64:
    versionStr = fmt.Sprintf("%d", v)
case float64:
    versionStr = fmt.Sprintf("%g", v)
}

After:

versionStr := stringutil.ParseVersionValue(version)

Note: Placed in pkg/stringutil (not pkg/workflow/config_helpers) to avoid circular import between workflowparser packages.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/user
    • Triggering command: /usr/bin/gh gh api user --jq .login -json GO111MODULE 0.1-go1.25.0.linGOMODCACHE GOINSECURE GOMOD GOMODCACHE /home/REDACTED/go/GO111MODULE -V=f�� GOPATH GOPROXY ux-amd64/pkg/tool/linux_amd64/vet GOSUMDB GOWORK pkg/mod/golang.oGOPATH ux-amd64/pkg/tool/linux_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh api user --jq .login ithub/workflows -test.v=true /home/REDACTED/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/pkg/tool/linux_amd64/co/tmp/validate-js-2645958109.cjs -test.run=^Test GOWORK l/linux_amd64/cgo /home/REDACTED/go/pkg/mod/golang.o/tmp/gh-aw/aw.patch -o k/gh-aw/gh-aw/.github/workflows -trimpath ps by/68235995b14f8gh main -lang=go1.25 ps (http block)
    • Triggering command: /usr/bin/gh gh api user --jq .login ithub/workflows go ps -json GO111MODULE ux-amd64/bin/go ps -pyt�� -python.git /home/REDACTED/go/GO111MODULE (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Create reusable parseVersionValue helper function</issue_title>
<issue_description>## Objective

Create a reusable helper function for parsing version values to reduce code duplication and ensure consistent type handling across the codebase.

Context

The same type coercion logic (string/int/float → string) is duplicated across three locations. Creating a shared helper promotes DRY principles and makes future maintenance easier.

Proposed Implementation

Add to pkg/workflow/config_helpers.go:

// parseVersionValue converts version values of various types to strings.
// Supports string, int, int64, uint64, and float64 types.
// Returns empty string for unsupported types.
func parseVersionValue(version any) string {
    switch v := version.(type) {
    case string:
        return v
    case int, int64, uint64:
        return fmt.Sprintf("%d", v)
    case float64:
        return fmt.Sprintf("%g", v)
    default:
        return ""
    }
}

Refactor Usage Sites

Update the three fixed locations to use the helper:

1. engine.go:

if version, hasVersion := engineObj["version"]; hasVersion {
    config.Version = parseVersionValue(version)
}

2. mcp.go (GitHub MCP, line 372):

if version, exists := toolConfig["version"]; exists {
    if versionStr := parseVersionValue(version); versionStr != "" {
        dockerImage := "ghcr.io/github/github-mcp-server:" + versionStr
    }
}

3. mcp.go (Playwright, line 447):

if version, exists := toolConfig["version"]; exists {
    if versionStr := parseVersionValue(version); versionStr != "" {
        // Version handling logic
    }
}

Files to Modify

  • Update: pkg/workflow/config_helpers.go (add helper function)
  • Update: pkg/workflow/config_helpers_test.go (add tests)
  • Update: pkg/workflow/engine.go (refactor to use helper)
  • Update: pkg/parser/mcp.go (refactor two locations to use helper)

Acceptance Criteria

  • Helper function is added to config_helpers.go
  • Helper function has unit tests
  • All three version field locations use the helper
  • Existing tests continue to pass
  • Code duplication is eliminated

Estimated Effort

~20 minutes implementation

Dependencies

Should be completed after sub-issues #1, #2, and #3 are fixed.
Related to #8221

AI generated by Plan Command for discussion #8218

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Create reusable parseVersionValue helper function Add ParseVersionValue helper to eliminate version parsing duplication Dec 31, 2025
Copilot AI requested a review from mnkiefer December 31, 2025 02:59
@pelikhan pelikhan marked this pull request as ready for review December 31, 2025 03:01
@pelikhan pelikhan merged commit 0905fe4 into main Dec 31, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/create-parse-version-value-helper branch December 31, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Create reusable parseVersionValue helper function

3 participants